package com.fubowen.reader.db.bean

import android.view.View
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import com.fubowen.reader.adapter.ISimple
import com.fubowen.reader.databinding.HistoriesBinding
import com.fubowen.reader.extension.setImageByteArray
import com.fubowen.reader.db.model.Tree

@Entity(indices = [Index(value = ["url"], unique = true)])
class WebSiteBean @JvmOverloads constructor(
    var name: String? = null,
    var description: String? = null,
    var url: String = "",
    var keywords: String? = null,
    var favicon: ByteArray? = null,
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0,
    var timestamp: Long = System.currentTimeMillis()
) : ISimple<WebSiteBean> {

    @Ignore
    var children: List<Tree> = mutableListOf()

    override fun isSame(new: WebSiteBean) = url == new.url

    override fun isSameOfContent(new: WebSiteBean) = url == new.url

    override fun onBind(view: View, id: Int) {
        val binding = HistoriesBinding.bind(view)
        binding.name.text = name
        binding.url.text = url
        binding.favicon.setImageByteArray(favicon)
    }
}